// api/api.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    latitude: 0,
    longitude: 0,
    imgList: [],
    proList:[]
  },
  getLocation() {
    altitude: 0,
      wx.getLocation({
        success: (res) => {
          console.log(res);
          this.setData({
            longitude: res.longitude,
            latitude: res.latitude,
          });
        },
        fail(err) {
          console.log(err);
        },
      });
  },
  chooseLocation() {
    wx.chooseLocation({
      latitude: 30.305591,
      longitude: 120.265107,
      success: (res) => {
        this.setData({
          latitude: res.latitude,
          longitude: res.longitude,
        });
      },
      fail(err) {
        console.log(err);
      },
    });
  },
  // 扫二维码
  scanCode() {
    wx.scanCode({
      onlyFromCamera: false,
      success(res) {
        console.log(res);
      },
    });
  },

  // 拍照
  takePhoto() {
    console.log("takePhoto");

    const cameraCtx = wx.createCameraContext();
    console.log(cameraCtx);
    cameraCtx.takePhoto();
  },
  // 拍照或相册
  chooseMedia() {
    wx.chooseMedia({
      count: 9,
      success: (res) => {
        // console.log(res.tempFiles[0].tempFilePath);
        this.setData({
          imgList: res.tempFiles,
        });
      },
      fail(res) {
        console.log(res);
      },
    });
  },
  // 获取用户信息
  getUerIns() {
    wx.requestPayment({
      timeStamp: Date.now(),
      nonceStr: "2135156w4sAGQWGD8AN",
      package: "prepay_id=wx20191021170801f0f0c0c00001c01c01c",
      paySign: "wx20191021170801f0f0c0c00001c01c01c",
      success: (res) => {
        console.log(res);
      },
      fail(res) {
        console.log(res);
      },
    });
    // 登录
    // wx.login({
    //   success: (res) => {
    //     // 发送 res.code 到后台换取 openId, sessionKey, unionId
    //     wx.getUserInfo({
    //       lang: "zh_CN",
    //       success: (res) => {
    //         console.log(JSON.parse(res.rawData));
    //       },
    //     });
    //   },
    // });
  },

  //sendRequest发送数据请求
  sendRequest(){
    wx.request({
      url:'http://10.31.155.245:3000/api/pro/list',
      success:(res)=>{
        console.log(res.data);
        this.setData({
          proList:res.data.data
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
